package com.bh.statistics.controller;

import com.bh.statistics.entity.Result;
import com.bh.statistics.entity.TBcast;
import com.bh.statistics.entity.TBcastVO;
import com.bh.statistics.service.BroadcastService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * ApiController 暴露接口
 *
 * @author bh_ljy
 * @version 2023/11/22 18:27
 **/
@RestController
@RequestMapping("/api/v1")
@Slf4j
public class ApiController {
    @Resource
    BroadcastService broadcastService;

    @GetMapping("/connect")
    public Result connect() {
        return Result.succeed("接口联通成功!");
    }

    @PostMapping("/getBroadcastHistory")
    public Result getBroadcastHistory(@RequestParam HashMap<String, String> mapinfo) {
        String sourceCode="F45101130000000314010202";
        String startTime = mapinfo.get("startTime");
        String endTime = mapinfo.get("endTime");
        if(startTime==null){
            Result.fail(500,"开始时间不能为空");
        }
        if(endTime==null){
            Result.fail(500,"结束时间不能为空");
        }
        if(mapinfo.get("sourceCode")!=null){
            sourceCode = mapinfo.get("sourceCode");
        }
        List<TBcastVO> broadcastHistory = broadcastService.getBroadcastHistory(sourceCode,startTime, endTime);
        return Result.succeed("查询成功!",broadcastHistory);
    }
    @GetMapping("/getBroadcastAdapter")
    public Result getBroadcastAdapter(@RequestParam HashMap<String, String> mapinfo) {
        String sourceCode="F45101130000000314010202";
        if(mapinfo.get("sourceCode")!=null){
            sourceCode = mapinfo.get("sourceCode");
        }
        List<TBcastVO> broadcastHistory = broadcastService.getBroadcastAdapter(sourceCode);
        return Result.succeed("查询成功!",broadcastHistory);
    }

}
